package com.cac.demo.controller.logMonitor;


import com.cac.demo.service.logMonitor.ErpLogService;
import com.cac.demo.util.adapter.ResponseMsg;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/erpLogRest")
public class ErpLogRest {
    @Autowired
    private ErpLogService erpLogService;

    @PostMapping("querySendErpLog")
    public PageInfo querySendErpLog(@RequestBody HashMap param) {
        HashMap queryParam = (HashMap) param.get("queryParam");
        HashMap page = (HashMap) param.get("page");
        int startPage = Integer.parseInt(page.get("currentPage").toString());
        int pageSize = Integer.parseInt(page.get("pageSize").toString());
        return erpLogService.querySendErpLog(startPage, pageSize, queryParam);
    }

    @PostMapping("queryBackLog")
    public PageInfo queryBackLog(@RequestBody HashMap param) {
        HashMap queryParam = (HashMap) param.get("queryParam");
        HashMap page = (HashMap) param.get("page");
        int startPage = Integer.parseInt(page.get("currentPage").toString());
        int pageSize = Integer.parseInt(page.get("pageSize").toString());
        return erpLogService.queryBackLog(startPage, pageSize, queryParam);
    }

    @PostMapping("/updateMsg")
    public ResponseMsg updateMsg(@RequestBody HashMap map) {
        ResponseMsg responseMsg = new ResponseMsg();
        if(Objects.isNull(map)){
            return responseMsg.setRetCode("201").setMessage("未找到数据");
        }
        responseMsg=erpLogService.updateMsg(map);
        return responseMsg;
    }
    @PostMapping("/deleteLog")
    public ResponseMsg deleteLog(@RequestBody List<HashMap> list) {
        ResponseMsg responseMsg = new ResponseMsg();
        responseMsg=erpLogService.deleteLog(list);
        return responseMsg;
    }

    @PostMapping("/searchMsgToTime")
    public PageInfo searchMsgToTime(@RequestBody HashMap param) {
        HashMap queryParam = (HashMap) param.get("queryParam");
        HashMap page = (HashMap) param.get("page");
        int startPage = Integer.parseInt(page.get("currentPage").toString());
        int pageSize = Integer.parseInt(page.get("pageSize").toString());
        return erpLogService.searchMsgToTime(startPage, pageSize, queryParam);
    }

    /***
     * 推送指定的数据
     * ***/
    @PostMapping("reSendLog")
    public ResponseMsg reSendLog(@RequestBody List<HashMap> list){
        return erpLogService.reSendLog(list);
    }

}
